using System;
using System.IO;
using log4net;
using log4net.Appender;

namespace Wra4Skype.Library
{
    public class Logger : ILogger
    {
        private readonly ILog logger;

        public Logger()
        {
            // load configuration
            var logConfigStream = typeof(Logger).Assembly.GetManifestResourceStream("Wra4Skype.Library.LogConfig.xml");
            log4net.Config.XmlConfigurator.Configure(logConfigStream);

            // get logger instance
            this.logger = LogManager.GetLogger("Default");

            // set logger location
            foreach (var appender in this.logger.Logger.Repository.GetAppenders())
            {
                var fileAppender = appender as FileAppender;
                if (fileAppender != null)
                {
                    fileAppender.File = LogFile;
                }
            }
        }

        public static string LogFile
        {
            get
            {
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Wra4Skype\Wra4Skype.log");
            }
        }

        public void Info(string message)
        {
            this.logger.Info(message);
        }

        public void Error(string message)
        {
            this.logger.Error(message);
        }

        public void Error(string message, Exception exception)
        {
            this.logger.Error(message, exception);
        }

        public void Debug(string message)
        {
            this.logger.Debug(message);
        }

        public void Warn(string message)
        {
            this.logger.Warn(message);
        }

        public void Warn(string message, Exception exception)
        {
            this.logger.Warn(message, exception);
        }
    }
}